home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 102642.2026@compuserve.com (Ja Uhm)
- Newsgroups: comp.lang.c
- Subject: Re: How to dynamically allocate first element of linked list.
- Date: 11 Jan 1996 23:59:54 GMT
- Organization: soflogic
- Message-ID: <4d489q$7qg@dub-news-svc-5.compuserve.com>
- References: <erkDL007G.rt@netcom.com>
- NNTP-Posting-Host: ad45-164.compuserve.com
- X-Newsreader: WinVN 0.90.5
-
- In article <erkDL007G.rt@netcom.com>, erk@netcom.com (Staugher) says:
- >
- >Im trying (without any luck )to write a function to allocate the first element
- >of a doubly linked list in C++. Unfortunately I learned data structures in
- >Pascal and have to port my knowledge (or lack of ) to C.
- >
- >Here is my arrangement:
- >
- >
- >struct elmnt
- > { char name[20];
- > char number[17];
- > struct elmnt *forward_pointer;
- > struct elmnt *reverse_pointer;
- > }
- >
- >newptr = malloc(sizeof(struct elmnt));
-
-
- You must cast the return from malloc to the type (elmnt *) .
-
- Therefore use:
-
- newptr = (elmnt *) malloc(sizeof(struct elmnt));
-
-
- Ja Uhm
-